package com.mg.g2048.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.mg.g2048.R;

public class ShareAdapter extends BaseAdapter {
	Context context = null;
	float width = 0;
	String[] nameStr = null;
	int[] src = null;
	OnClickListener clickListener = null;
	
	public ShareAdapter(Context context,OnClickListener clickListener, float width, String[] nameStr, int src[]){
		this.nameStr = nameStr;
		this.context = context;
		this.width = width;
		this.src = src;
		this.clickListener = clickListener;
	}
	@Override
	public int getCount() {
		if(nameStr == null)
			return 0;
		else
			return nameStr.length;
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup parent) {
		LayoutInflater inflater = LayoutInflater.from(context);  
		
		View item = inflater.inflate(R.layout.share_item, parent, false); 
		TextView title = (TextView) item.findViewById(R.id.title);
		ImageView icon = (ImageView) item.findViewById(R.id.icon);
		
		LayoutParams params = item.getLayoutParams();
		params.height = (int) width;
		item.setLayoutParams(params);
		
		icon.setImageResource(src[arg0]);
		title.setText(nameStr[arg0]);
		item.setId(arg0);
		item.setOnClickListener(clickListener);
		
		return item;
	}

}
